package com.c.ctgproject.wiget.common

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import com.c.ctgproject.R
import com.c.ctgproject.utils.myShake
import com.c.ctgproject.utils.showToast
import kotlinx.android.synthetic.main.layout_dialog_input.*

/**
 *作者:LiBW
 *创建日期: 2021/7/9
 *描述:通用输入 弹窗 传入回调 标题 输入框提示
 */
class CommonInputDialog(private val callback: CommonInPutDialogCallBack, private var title:String, private val hint:String?=null) : DialogFragment() {

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.layout_dialog_input_common, container, false)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(STYLE_NORMAL, R.style.inputDialog)
    }


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        mTitleTV.text=title
        val mHint= hint ?: "请输入$title"
        mOpinionET.hint=mHint
        mConfirmRL.setOnClickListener {
            val msg = mOpinionET.text.toString()
            if (msg.isEmpty()) {
                mOpinionET.myShake()
                requireContext().showToast(mHint)
            } else {
                callback.dialogResultText(msg)
            }
        }
    }

    interface CommonInPutDialogCallBack {
        fun dialogResultText(msg: String)
    }
}